import { ref, computed } from 'vue'
import { defineStore } from 'pinia'

export const useCounterStore = defineStore('counter', () => {
  let counter = ref([])
  function counterAdd(detail, goods_id) {
    let pacat = counter.value.find(item => item.goods.goods_id == goods_id)
    if (pacat) {
      pacat.number++
    } else {
      counter.value.push({
        username: localStorage.getItem('username'),
        id: Math.floor(Math.random() * 100000),
        goods:detail,
        number:1,
        checked:false,
      })
    }
  }
  return { counter, counterAdd }
},
  {
    persist: true,
  },

)
